package com.sds.batch.sample;

import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;

import java.util.Iterator;

import org.junit.Test;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;

import com.sds.batch.util.BatchUtil;

@ContextConfiguration(locations={
		"classpath:spring/context-datasource.xml",
		"classpath:spring/context-batch.xml",
		"classpath:com/sds/batch/sample/tasklet_Job.xml"})
public class SimpleCalledTaskletTests extends AbstractJUnit4SpringContextTests {
	@Autowired
	private JobLauncher launcher;
	@Autowired
	private Job job;
	
	@Test
	public void launchJob() throws Exception {
		JobExecution jobExecution = launcher.run(job, BatchUtil.getUniqueParameters(new JobParameters()));
		
		assertThat(jobExecution, not(nullValue()));
		
		for(Iterator<StepExecution> iterator = jobExecution.getStepExecutions().iterator();
			iterator.hasNext();) {
			StepExecution stepExecution = iterator.next();
		}
		
	}
}
